import request from '@/utils/request';
import { ConsultOrderPre, ConsultOrderPreParams, MedicineDetail, MedicinePage, MedicineParams, PartialConsult, PaymentParams } from '@/type/ConsultType';
import type { ResponseType } from '@/type/ResponseType';
import { OrderItem } from '@/type/ConsultOrder';

enum Enum {
  fetchConsultOrderPreAPI = '/patient/consult/order/pre',
  createConsultOrderAPI = '/patient/consult/order',
  paymentConsultOrderAPI = '/patient/consult/pay',
  fetchMedicineListAPI = 'patient/medicine',
  findMedicineDetailAPI = 'patient/medicine',
  fetchOrderDetailAPI = '/patient/consult/order/detail'
}

/**
 * @description 保存/修改问诊订单的接口
 * */
export const createConsultOrderAPI = async (data: PartialConsult) => request.post<{ id: string }, ResponseType<{ id: string }>>(Enum.createConsultOrderAPI, data);

/**
 * @description 获取预支付订单信息的接口
 * */
export const fetchConsultOrderPreAPI = (params: ConsultOrderPreParams) => request.get<ConsultOrderPre, ResponseType<ConsultOrderPre>>(Enum.fetchConsultOrderPreAPI, { params });

/**
 * @description 订单支付的接口
 * */
export const paymentConsultOrderAPI = (paymentParams: PaymentParams) => request.post<{ payUrl: string }, ResponseType<{ payUrl: string }>>(Enum.paymentConsultOrderAPI, paymentParams);

/**
 * @description 查询药品列表的回调函数
 * */
export const fetchMedicineListAPI = (medicineParams: MedicineParams) => request.get<MedicinePage, ResponseType<MedicinePage>>(Enum.fetchMedicineListAPI, { params: medicineParams });

/**
 * @description 查询药品详情的接口
 * */
export const findMedicineDetailAPI = (id: string) => request.get<MedicineDetail, ResponseType<MedicineDetail>>(`${Enum.findMedicineDetailAPI}/${id}`);

/**
 * @description 查询订单详情信息的接口
 * */
export const fetchOrderDetailAPI = (orderId: string) => request.get<OrderItem, ResponseType<OrderItem>>(Enum.fetchOrderDetailAPI, { params: { orderId } });